package com.zhuss.core.part;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.part.DetailPartBo;
import com.zhuss.bean.bo.core.part.SearchPartBo;
import com.zhuss.bean.bo.core.upload.DownloadBo;
import com.zhuss.bean.vo.core.part.DetailPartVo;
import com.zhuss.bean.vo.core.part.ListPartVo;
import com.zhuss.bean.vo.core.upload.DownloadVo;
import com.zhuss.common.PageVo;
import com.zhuss.common.Processor;
import com.zhuss.common.ReadService;
import com.zhuss.core.processor.PartRead;
import com.zhuss.exception.WpsException;


/**
 * 区域查询service（基本查询）
 * @author zhushanshuo
 * @Date 2020-02-05 15:59
 *
 */
@Component("partReadService")
public class PartReadService implements ReadService<Object, Object> {
	
	@Autowired
	@Qualifier("partRead")
	private PartRead partRead;
	
	@Autowired
	@Qualifier("downloadProcessor")
	private Processor<DownloadVo, DownloadBo> downloadProcessor;
	
	/**
	 * 区域下拉框
	 * @return
	 */
	public Object areaList() {
		return partRead.areaList();
	}
	
	/**
	 * 详情
	 */
	@Override
	public Object detail(Object param) throws WpsException {
		DetailPartBo bo = (DetailPartBo) param;
		Long partId = bo.getPartId();
		DetailPartVo vo = (DetailPartVo) partRead.detail(partId);
		
		DownloadBo downloadBo = new DownloadBo();
		downloadBo.setKeyList(vo.getPic());
		DownloadVo downloadVo = downloadProcessor.process(downloadBo);
		vo.setUrlList(downloadVo.getUrlList());
		
		return vo;
	}
	
	/**
	 * 列表
	 * @throws WpsException 
	 */
	@Override
	public Object list(Object param) throws WpsException {
		SearchPartBo bo = (SearchPartBo) param;
		Object result = partRead.list(bo);
		transfer(result);
		return result;
	}

	@SuppressWarnings("unchecked")
	private void transfer(Object result) throws WpsException {
		PageVo<ListPartVo> pageVo = (PageVo<ListPartVo>) result;
		for (ListPartVo vo : pageVo.getItems()) {
			DownloadBo downloadBo = new DownloadBo();
			downloadBo.setKeyList(vo.getPic());
			DownloadVo downloadVo = downloadProcessor.process(downloadBo);
			vo.setUrlList(downloadVo.getUrlList());
			
		}
	}
	
}

